import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:hugeicons/hugeicons.dart';
import 'package:provider/provider.dart';
import '../../base/base_widget.dart';
import '../../resources.dart';
import 'model/mine_model.dart';

/// created by hcl
/// on 2024/6/1
/// MinePage
/// desc
class MinePage extends StatefulWidget {
  const MinePage({super.key});

  @override
  State<StatefulWidget> createState() => MineState();
}

class MineState extends BaseWidgetState<MineModel, MinePage> {
  @override
  bool get wantKeepAlive => true;

  @override
  MineModel initModel() {
    return MineModel();
  }

  @override
  Widget bodyWidget(BuildContext context) {
    return GestureDetector(
      onTap: () {
        hideKeyboard();
      },
      child: Container(
        width: designWidth.ss,
        height: double.infinity,
        color: Colors.transparent,
        child: Column(
          children: [
            commonTitleBar(word.mine,
                titleBackColor: ColorUtils.color_F36371),
            Expanded(
              child: _buildList(),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildList() {
    return SingleChildScrollView(
      child: Container(
        padding: EdgeInsets.only(top: 16.5.ss, left: 13.ss, right: 9.ss),
        child: Column(
          children: [
            _buildTop(),
            SizedBox(height: 26.ss),
            // _callNumber('0539665766');
            buildRow(HugeIcons.strokeRoundedCirclePassword, '安全密码', () {
              model.goChangePassword();
            }),
            SizedBox(height: 8.ss),
            buildRow(HugeIcons.strokeRoundedUserAccount, '检查更新', () {
              model.goAbout();
            }),
            SizedBox(height: 8.ss),
            buildRow(HugeIcons.strokeRoundedClean, '清空缓存', () {
              model.goClear();
            }),
            // buildRow(ImageUtils.icon_logout, word.sign_out, () {
            //   Toast.showYesNoColor(
            //       title: word.sign_out_sure,
            //       content: word.signout_tips,
            //       confirmFunc: () {
            //         model.goSignout();
            //       });
            // }),
          ],
        ),
      ),
    );
  }

  Widget _buildTop() {
    return Consumer<MineModel>(
        builder: (BuildContext context, model, Widget? child) {
      return Container(
        padding: EdgeInsets.all(15.ss),
        decoration: BoxDecoration(
          color: ColorUtils.color_F36371.withOpacity(0.1),
          borderRadius: BorderRadius.circular(8.ss),
          boxShadow: [
            BoxShadow(
              color: ColorUtils.color_F36371.withOpacity(0.05),
              blurRadius: 5.0,
              offset: Offset(5.ss, 5.ss),
            ),
          ],
        ),
        child: Row(
          children: [
            Container(
                width: 47.ss,
                height: 47.ss,
                clipBehavior: Clip.hardEdge,
                decoration: BoxDecoration(
                    color: ColorUtils.color_F36371.withOpacity(0.3),
                    borderRadius: BorderRadius.circular(47.ss),
                    border: Border.all(
                        color: ColorUtils.color_F36371.withOpacity(0.4))),
                child: Container(
                  width: 46.ss,
                  height: 46.ss,
                  clipBehavior: Clip.hardEdge,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(46.ss),
                  ),
                  child: assetImage(ImageUtils.default_bitmap,
                      width: 46.ss, height: 46.ss),
                )),
            SizedBox(width: 8.ss),
            Expanded(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  Row(
                    children: [
                      Text('昵称${word.mao}',
                          style: normal712.copyWith(height: 1.2)),
                      Expanded(
                          child: Text(model.name.isNotEmpty ? model.name : '-',
                              style: normal012.copyWith(height: 1.2))),
                    ],
                  ),
                  SizedBox(height: 8.ss),
                  Row(
                    children: [
                      Text('账号${word.mao}',
                          style: normal712.copyWith(height: 1.2)),
                      Expanded(
                          child: Text(model.account,
                              style: normal012.copyWith(height: 1.2))),
                    ],
                  ),
                ],
              ),
            ),
          ],
        ),
      );
    });
  }

  Widget _buildButtonItem(
      String image, String title, GestureTapCallback onTap) {
    return InkWell(
      onTap: onTap,
      child: Container(
        alignment: Alignment.center,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            assetImage(image, width: 32.ss, height: 32.ss, fit: BoxFit.contain),
            SizedBox(height: 10.ss),
            Text(title, style: normal316),
          ],
        ),
      ),
    );
  }

  Widget buildRow(IconData icon, String title, Function() onTap,
      {bool showRight = true}) {
    return InkWell(
      onTap: onTap,
      hoverColor: ColorUtils.color_FFFFFF.withOpacity(0.1),
      borderRadius: BorderRadius.circular(8.ss),
      child: Container(
        height: 56.ss,
        padding: EdgeInsets.all(15.ss),
        decoration: BoxDecoration(
          color: ColorUtils.color_F36371.withOpacity(0.1),
          borderRadius: BorderRadius.circular(8.ss),
          boxShadow: [
            BoxShadow(
              color: ColorUtils.color_F36371.withOpacity(0.05),
              blurRadius: 5.0,
              offset: Offset(5.ss, 5.ss),
            ),
          ],
        ),
        child: Row(
          children: [
            HugeIcon(icon: icon, color: ColorUtils.color_333333, size: 18.ss),
            SizedBox(width: 8.ss),
            Text(title, style: normal314),
            const Spacer(),
          ],
        ),
      ),
    );
  }

  _callNumber(String number) async {
    // await FlutterPhoneDirectCaller.callNumber(number);
  }

  copyData(String content) {
    if (content.isNotEmpty) {
      Clipboard.setData(ClipboardData(text: content));
      model.showToast(word.copy_success);
    } else {
      model.showToast(word.copy_failed);
    }
  }

// Widget buildRow(String image, String title, Function() onTap,
//     {bool showRight = false}) {
//   return InkWell(
//     onTap: onTap,
//     child: Container(
//       padding: EdgeInsets.symmetric(vertical: 8.ss, horizontal: 5.ss),
//       decoration: const BoxDecoration(
//           color: ColorUtils.color_FFFFFF,
//           border:
//               Border(bottom: BorderSide(color: ColorUtils.color_66666666))),
//       child: Row(
//         children: [
//           assetImage(image, width: 28.ss, height: 28.ss),
//           SizedBox(width: 5.ss),
//           Text(title, style: normalB014),
//           const Spacer(),
//           showRight ? assetImage(ImageUtils.arrow_right_black) : SizedBox(),
//         ],
//       ),
//     ),
//   );
// }
}
